//
//  RegionContentCell.m
//  HTHappySale
//
//  Created by 创维海通 on 2017/9/21.
//  Copyright © 2017年 zxyywy. All rights reserved.
//

#import "RegionContentCell.h"
@interface RegionContentCell()
@property (strong, nonatomic) IBOutlet UIButton *city1Btn;
@property (strong, nonatomic) IBOutlet UIButton *city2Btn;
@property (strong, nonatomic) IBOutlet UIButton *city3Btn;

@property (strong, nonatomic) Region2Model *modelCell;

@end

@implementation RegionContentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)configureCell:(NSArray<Region2Model *>*)paramsArr AtWithIndex:(NSInteger)index AtWithSelectModel:(Region2Model *)selectModel{
    unsigned long cutLen = 0;
    if(index==0){
        cutLen = paramsArr.count;
    }else{
        if(index * 3 > paramsArr.count)
        {
            cutLen = 3 - (index * 3 - paramsArr.count);
        }else{
            cutLen = 3;
        }
    }
    
    NSArray<Region2Model *>* tempArr = [[NSArray alloc] initWithArray:[paramsArr subarrayWithRange:NSMakeRange(index * 3, cutLen)]];
    
    for (int i = 0; i < tempArr.count; i++) {
        _modelCell = [[Region2Model alloc] init];
        _modelCell = tempArr[i];
        
        if (i == 0) {
            [_city1Btn setTitle:_modelCell.name forState:UIControlStateNormal];
            _city1Btn.layer.borderColor = [UIColor blackColor].CGColor;//设置边框颜色
            _city1Btn.layer.borderWidth = 1.0f;//设置边框颜色
            _city1Btn.tag = 200 + index * 3 + i;
            
            [_city1Btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
            [_city1Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [_city1Btn addTarget:self action:@selector(clickTag:) forControlEvents:UIControlEventTouchUpInside];
            [self compareTag:_city1Btn AtWithParamId:[_modelCell.rId intValue] AtWithTransmitParams:selectModel];
        }else if (i == 1){
            [_city2Btn setTitle:_modelCell.name forState:UIControlStateNormal];
            _city2Btn.layer.borderColor = [UIColor blackColor].CGColor;//设置边框颜色
            _city2Btn.layer.borderWidth = 1.0f;//设置边框颜色
            _city2Btn.tag = 200 + index * 3 + i;
            [_city2Btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
            [_city2Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [_city2Btn addTarget:self action:@selector(clickTag:) forControlEvents:UIControlEventTouchUpInside];
            
            [self compareTag:_city2Btn AtWithParamId:[_modelCell.rId intValue] AtWithTransmitParams:selectModel];
        }else if (i == 2){
            [_city3Btn setTitle:_modelCell.name forState:UIControlStateNormal];
            _city3Btn.layer.borderColor = [UIColor blackColor].CGColor;//设置边框颜色
            _city3Btn.layer.borderWidth = 1.0f;//设置边框颜色
            _city3Btn.tag = 200 + index * 3 + i;
            [_city3Btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
            [_city3Btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            
            [_city3Btn addTarget:self action:@selector(clickTag:) forControlEvents:UIControlEventTouchUpInside];
            
            [self compareTag:_city3Btn AtWithParamId:[_modelCell.rId intValue] AtWithTransmitParams:selectModel];
        }
    }
}

- (void)compareTag:(UIButton *)btn AtWithParamId:(int)compId AtWithTransmitParams:(Region2Model *)transmitParam{
    if(transmitParam != nil && [transmitParam.rId intValue] == compId)
    {
        btn.selected = YES;
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setBackgroundColor:HTCFQuickRGBColor(32,170,255)];
    }
}

- (void)clickTag:(UIButton *)button{
    
    if ([_delegate respondsToSelector:@selector(transmitTag:)]) {
        [_delegate transmitTag:(int)button.tag];
    }
}

@end
